home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / FILEBKUP.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  3KB  |  108 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       f i l e b k u p                                              */
  3. /*                                                                    */
  4. /*       UUPC/extended file backup routines                           */
  5. /*                                                                    */
  6. /*       Copyright (c) 1991-1993 by Andrew H. Derbyshire;             */
  7. /*       all rights reserved except as granted by UUPC/extended       */
  8. /*       license included with documention.                           */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*                          RCS Information                           */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*
  16.  *    $Id: FILEBKUP.C 1.3 1993/04/11 00:33:38 dmwatt Exp $
  17.  *
  18.  *    Revision history:
  19.  *    $Log: FILEBKUP.C $
  20.  *     Revision 1.3  1993/04/11  00:33:38  dmwatt
  21.  *     Global edits for year, TEXT, etc.
  22.  *
  23.  * Revision 1.2  1992/11/19  02:57:51  ahd
  24.  * drop rcsid
  25.  *
  26.  * Revision 1.1  1992/11/16  05:00:26  ahd
  27.  * Initial revision
  28.  *
  29.  */
  30.  
  31.  
  32.  
  33. /*--------------------------------------------------------------------*/
  34. /*                        System include files                        */
  35. /*--------------------------------------------------------------------*/
  36.  
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <time.h>
  41.  
  42. #ifndef __GNUC__
  43. #include <direct.h>
  44. #endif
  45.  
  46. /*--------------------------------------------------------------------*/
  47. /*                    UUPC/extended include files                     */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. #include "lib.h"
  51. #include "hlib.h"
  52.  
  53. currentfile();
  54.  
  55. /*--------------------------------------------------------------------*/
  56. /*    f i l e b k u p                                                 */
  57. /*                                                                    */
  58. /*    Backup a file to the standard UUPC/extended defined             */
  59. /*    extension.                                                      */
  60. /*--------------------------------------------------------------------*/
  61.  
  62. int filebkup( const char *input )
  63. {
  64.    char fdrive[FILENAME_MAX];
  65.    char fpath[FILENAME_MAX];
  66.    char fname[FILENAME_MAX];
  67.    char ftype[FILENAME_MAX];
  68.    char backup[FILENAME_MAX];
  69.  
  70.    if ( !bflag[F_BACKUP] )    /* Are we to not back it up?           */
  71.       return 1;               /* Yes --> Report we did not           */
  72.  
  73. #ifdef __TURBOC__
  74.    fnsplit( input, fdrive, fpath, fname, ftype );
  75.  
  76.    if ( E_backup == NULL )
  77.       strcpy(ftype, ".BAK" );
  78.    else if ( *E_backup == '.' )
  79.       strcpy( ftype, E_backup );
  80.    else {
  81.       *ftype = '.';
  82.       strcpy(  ftype + 1 , E_backup );
  83.    } /* else */
  84.  
  85.    fnmerge( backup, fdrive, fpath, fname, ftype );
  86. #else
  87.  
  88.    if ( E_backup == NULL )
  89.       E_backup = ".BAK";
  90.  
  91.    _splitpath( input , fdrive, fpath, fname, ftype );
  92.    _makepath( backup , fdrive, fpath, fname, E_backup );
  93. #endif /* __TURBOC__ */
  94.  
  95.    remove( backup );
  96.  
  97.    if (rename( input, backup ))
  98.    {
  99.       printerr( backup );
  100.       printmsg(1,"Unable to rename %s to %s\n", input, backup );
  101.       return 1;
  102.  
  103.    } /* if (rename( input, backup )) */
  104.    else
  105.       return 0;
  106.  
  107. } /* filebkup */
  108.